package com.ruoyi.service.region.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.service.region.entity.RegionEntity;
import com.ruoyi.service.region.enums.RegionLevel;
import com.ruoyi.service.region.mapper.RegionMapper;
import com.ruoyi.service.region.service.RegionService;
import java.util.List;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 省市县表 服务实现类
 * </p>
 *
 * @author Zane
 * @since 2025-10-05
 */
@Service
public class RegionServiceImpl extends ServiceImpl<RegionMapper, RegionEntity> implements
    RegionService {

  @Override
  public List<RegionEntity> getProvince() {
    return baseMapper.selectList(effectQuery()
        .eq(RegionEntity::getLevel, RegionLevel.PROVINCE.getCode()));
  }

  @Override
  public List<RegionEntity> getCity(Integer provinceId) {
    return baseMapper.selectList(effectQuery()
        .eq(RegionEntity::getPid, provinceId)
        .eq(RegionEntity::getLevel, RegionLevel.CITY.getCode()));
  }

  @Override
  public List<RegionEntity> getCounty(Integer cityId) {
    return baseMapper.selectList(effectQuery()
        .eq(RegionEntity::getPid, cityId)
        .eq(RegionEntity::getLevel, RegionLevel.COUNTY.getCode()));
  }

  @Override
  public List<RegionEntity> getAllCities() {
    return baseMapper.selectList(effectQuery()
        .eq(RegionEntity::getLevel, RegionLevel.CITY.getCode()));
  }

  private LambdaQueryWrapper<RegionEntity> effectQuery() {
    return new LambdaQueryWrapper<RegionEntity>()
        .eq(RegionEntity::getIsDelete, 0);
  }
}
